{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.model_selection import train_test_split\n",
    "from csv import reader\n",
    "from random import randrange\n",
    "from math import sqrt\n",
    "from sklearn.metrics import accuracy_score, classification_report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def predict(row, coefficients):\n",
    "    yhat = coefficients[0]\n",
    "    for i in range(len(row)-1):\n",
    "        yhat += coefficients[i + 1] * row[i]\n",
    "    return yhat\n",
    "\n",
    "def coefficients_sgd(train, l_rate, n_epoch):\n",
    "    coef = [0.0 for i in range(len(train[0]))]\n",
    "    \n",
    "    for epoch in range(n_epoch):\n",
    "        sum_error = 0\n",
    "        for row in train:\n",
    "            yhat = predict(row, coef)\n",
    "            error = yhat - row[-1]\n",
    "            sum_error += error**2\n",
    "            coef[0] = coef[0] - l_rate * error\n",
    "            for i in range(len(row)-1):\n",
    "                coef[i + 1] = coef[i + 1] - l_rate * error * row[i] \n",
    "        \n",
    "    return coef"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Fixed acidity</th>\n",
       "      <th>Volatile acidity</th>\n",
       "      <th>Citric acid</th>\n",
       "      <th>Residual sugar</th>\n",
       "      <th>Chlorides</th>\n",
       "      <th>Free sulfur dioxide</th>\n",
       "      <th>Total sulfur dioxide</th>\n",
       "      <th>Density</th>\n",
       "      <th>pH</th>\n",
       "      <th>Sulphates</th>\n",
       "      <th>Alcohol</th>\n",
       "      <th>Quality</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7.0</td>\n",
       "      <td>0.270</td>\n",
       "      <td>0.36</td>\n",
       "      <td>20.70</td>\n",
       "      <td>0.045</td>\n",
       "      <td>45.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>1.00100</td>\n",
       "      <td>3.00</td>\n",
       "      <td>0.45</td>\n",
       "      <td>8.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6.3</td>\n",
       "      <td>0.300</td>\n",
       "      <td>0.34</td>\n",
       "      <td>1.60</td>\n",
       "      <td>0.049</td>\n",
       "      <td>14.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>0.99400</td>\n",
       "      <td>3.30</td>\n",
       "      <td>0.49</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8.1</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.40</td>\n",
       "      <td>6.90</td>\n",
       "      <td>0.050</td>\n",
       "      <td>30.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>0.99510</td>\n",
       "      <td>3.26</td>\n",
       "      <td>0.44</td>\n",
       "      <td>10.100000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7.2</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.32</td>\n",
       "      <td>8.50</td>\n",
       "      <td>0.058</td>\n",
       "      <td>47.0</td>\n",
       "      <td>186.0</td>\n",
       "      <td>0.99560</td>\n",
       "      <td>3.19</td>\n",
       "      <td>0.40</td>\n",
       "      <td>9.900000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7.2</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.32</td>\n",
       "      <td>8.50</td>\n",
       "      <td>0.058</td>\n",
       "      <td>47.0</td>\n",
       "      <td>186.0</td>\n",
       "      <td>0.99560</td>\n",
       "      <td>3.19</td>\n",
       "      <td>0.40</td>\n",
       "      <td>9.900000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>8.1</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.40</td>\n",
       "      <td>6.90</td>\n",
       "      <td>0.050</td>\n",
       "      <td>30.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>0.99510</td>\n",
       "      <td>3.26</td>\n",
       "      <td>0.44</td>\n",
       "      <td>10.100000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.16</td>\n",
       "      <td>7.00</td>\n",
       "      <td>0.045</td>\n",
       "      <td>30.0</td>\n",
       "      <td>136.0</td>\n",
       "      <td>0.99490</td>\n",
       "      <td>3.18</td>\n",
       "      <td>0.47</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7.0</td>\n",
       "      <td>0.270</td>\n",
       "      <td>0.36</td>\n",
       "      <td>20.70</td>\n",
       "      <td>0.045</td>\n",
       "      <td>45.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>1.00100</td>\n",
       "      <td>3.00</td>\n",
       "      <td>0.45</td>\n",
       "      <td>8.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>6.3</td>\n",
       "      <td>0.300</td>\n",
       "      <td>0.34</td>\n",
       "      <td>1.60</td>\n",
       "      <td>0.049</td>\n",
       "      <td>14.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>0.99400</td>\n",
       "      <td>3.30</td>\n",
       "      <td>0.49</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>8.1</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.43</td>\n",
       "      <td>1.50</td>\n",
       "      <td>0.044</td>\n",
       "      <td>28.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>0.99380</td>\n",
       "      <td>3.22</td>\n",
       "      <td>0.45</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>8.1</td>\n",
       "      <td>0.270</td>\n",
       "      <td>0.41</td>\n",
       "      <td>1.45</td>\n",
       "      <td>0.033</td>\n",
       "      <td>11.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>0.99080</td>\n",
       "      <td>2.99</td>\n",
       "      <td>0.56</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>8.6</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.40</td>\n",
       "      <td>4.20</td>\n",
       "      <td>0.035</td>\n",
       "      <td>17.0</td>\n",
       "      <td>109.0</td>\n",
       "      <td>0.99470</td>\n",
       "      <td>3.14</td>\n",
       "      <td>0.53</td>\n",
       "      <td>9.700000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>7.9</td>\n",
       "      <td>0.180</td>\n",
       "      <td>0.37</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.040</td>\n",
       "      <td>16.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>0.99200</td>\n",
       "      <td>3.18</td>\n",
       "      <td>0.63</td>\n",
       "      <td>10.800000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.160</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1.50</td>\n",
       "      <td>0.044</td>\n",
       "      <td>48.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>0.99120</td>\n",
       "      <td>3.54</td>\n",
       "      <td>0.52</td>\n",
       "      <td>12.400000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>8.3</td>\n",
       "      <td>0.420</td>\n",
       "      <td>0.62</td>\n",
       "      <td>19.25</td>\n",
       "      <td>0.040</td>\n",
       "      <td>41.0</td>\n",
       "      <td>172.0</td>\n",
       "      <td>1.00020</td>\n",
       "      <td>2.98</td>\n",
       "      <td>0.67</td>\n",
       "      <td>9.700000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.170</td>\n",
       "      <td>0.38</td>\n",
       "      <td>1.50</td>\n",
       "      <td>0.032</td>\n",
       "      <td>28.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>0.99140</td>\n",
       "      <td>3.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>11.400000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>6.3</td>\n",
       "      <td>0.480</td>\n",
       "      <td>0.04</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.046</td>\n",
       "      <td>30.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>0.99280</td>\n",
       "      <td>3.24</td>\n",
       "      <td>0.36</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.660</td>\n",
       "      <td>0.48</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.029</td>\n",
       "      <td>29.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>0.98920</td>\n",
       "      <td>3.33</td>\n",
       "      <td>0.39</td>\n",
       "      <td>12.800000</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>7.4</td>\n",
       "      <td>0.340</td>\n",
       "      <td>0.42</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.033</td>\n",
       "      <td>17.0</td>\n",
       "      <td>171.0</td>\n",
       "      <td>0.99170</td>\n",
       "      <td>3.12</td>\n",
       "      <td>0.53</td>\n",
       "      <td>11.300000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>6.5</td>\n",
       "      <td>0.310</td>\n",
       "      <td>0.14</td>\n",
       "      <td>7.50</td>\n",
       "      <td>0.044</td>\n",
       "      <td>34.0</td>\n",
       "      <td>133.0</td>\n",
       "      <td>0.99550</td>\n",
       "      <td>3.22</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.660</td>\n",
       "      <td>0.48</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.029</td>\n",
       "      <td>29.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>0.98920</td>\n",
       "      <td>3.33</td>\n",
       "      <td>0.39</td>\n",
       "      <td>12.800000</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>6.4</td>\n",
       "      <td>0.310</td>\n",
       "      <td>0.38</td>\n",
       "      <td>2.90</td>\n",
       "      <td>0.038</td>\n",
       "      <td>19.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>0.99120</td>\n",
       "      <td>3.17</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>6.8</td>\n",
       "      <td>0.260</td>\n",
       "      <td>0.42</td>\n",
       "      <td>1.70</td>\n",
       "      <td>0.049</td>\n",
       "      <td>41.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>0.99300</td>\n",
       "      <td>3.47</td>\n",
       "      <td>0.48</td>\n",
       "      <td>10.500000</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>7.6</td>\n",
       "      <td>0.670</td>\n",
       "      <td>0.14</td>\n",
       "      <td>1.50</td>\n",
       "      <td>0.074</td>\n",
       "      <td>25.0</td>\n",
       "      <td>168.0</td>\n",
       "      <td>0.99370</td>\n",
       "      <td>3.05</td>\n",
       "      <td>0.51</td>\n",
       "      <td>9.300000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.270</td>\n",
       "      <td>0.41</td>\n",
       "      <td>1.30</td>\n",
       "      <td>0.052</td>\n",
       "      <td>16.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>0.99510</td>\n",
       "      <td>3.42</td>\n",
       "      <td>0.47</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>7.0</td>\n",
       "      <td>0.250</td>\n",
       "      <td>0.32</td>\n",
       "      <td>9.00</td>\n",
       "      <td>0.046</td>\n",
       "      <td>56.0</td>\n",
       "      <td>245.0</td>\n",
       "      <td>0.99550</td>\n",
       "      <td>3.25</td>\n",
       "      <td>0.50</td>\n",
       "      <td>10.400000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>6.9</td>\n",
       "      <td>0.240</td>\n",
       "      <td>0.35</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.052</td>\n",
       "      <td>35.0</td>\n",
       "      <td>146.0</td>\n",
       "      <td>0.99300</td>\n",
       "      <td>3.45</td>\n",
       "      <td>0.44</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>7.0</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.39</td>\n",
       "      <td>8.70</td>\n",
       "      <td>0.051</td>\n",
       "      <td>32.0</td>\n",
       "      <td>141.0</td>\n",
       "      <td>0.99610</td>\n",
       "      <td>3.38</td>\n",
       "      <td>0.53</td>\n",
       "      <td>10.500000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>7.4</td>\n",
       "      <td>0.270</td>\n",
       "      <td>0.48</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.047</td>\n",
       "      <td>17.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>0.99140</td>\n",
       "      <td>3.19</td>\n",
       "      <td>0.49</td>\n",
       "      <td>11.600000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>7.2</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.36</td>\n",
       "      <td>2.00</td>\n",
       "      <td>0.033</td>\n",
       "      <td>37.0</td>\n",
       "      <td>114.0</td>\n",
       "      <td>0.99060</td>\n",
       "      <td>3.10</td>\n",
       "      <td>0.71</td>\n",
       "      <td>12.300000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4868</th>\n",
       "      <td>5.8</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.31</td>\n",
       "      <td>4.50</td>\n",
       "      <td>0.046</td>\n",
       "      <td>42.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>0.99324</td>\n",
       "      <td>3.31</td>\n",
       "      <td>0.64</td>\n",
       "      <td>10.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4869</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.240</td>\n",
       "      <td>0.33</td>\n",
       "      <td>10.10</td>\n",
       "      <td>0.032</td>\n",
       "      <td>8.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>0.99626</td>\n",
       "      <td>3.19</td>\n",
       "      <td>0.51</td>\n",
       "      <td>9.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4870</th>\n",
       "      <td>6.1</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.28</td>\n",
       "      <td>6.60</td>\n",
       "      <td>0.021</td>\n",
       "      <td>29.0</td>\n",
       "      <td>132.0</td>\n",
       "      <td>0.99188</td>\n",
       "      <td>3.15</td>\n",
       "      <td>0.36</td>\n",
       "      <td>11.450000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4871</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.200</td>\n",
       "      <td>0.40</td>\n",
       "      <td>1.90</td>\n",
       "      <td>0.015</td>\n",
       "      <td>20.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>0.98970</td>\n",
       "      <td>3.37</td>\n",
       "      <td>0.55</td>\n",
       "      <td>12.050000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4872</th>\n",
       "      <td>6.0</td>\n",
       "      <td>0.420</td>\n",
       "      <td>0.41</td>\n",
       "      <td>12.40</td>\n",
       "      <td>0.032</td>\n",
       "      <td>50.0</td>\n",
       "      <td>179.0</td>\n",
       "      <td>0.99622</td>\n",
       "      <td>3.14</td>\n",
       "      <td>0.60</td>\n",
       "      <td>9.700000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4873</th>\n",
       "      <td>5.7</td>\n",
       "      <td>0.210</td>\n",
       "      <td>0.32</td>\n",
       "      <td>1.60</td>\n",
       "      <td>0.030</td>\n",
       "      <td>33.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>0.99044</td>\n",
       "      <td>3.33</td>\n",
       "      <td>0.52</td>\n",
       "      <td>11.900000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4874</th>\n",
       "      <td>5.6</td>\n",
       "      <td>0.200</td>\n",
       "      <td>0.36</td>\n",
       "      <td>2.50</td>\n",
       "      <td>0.048</td>\n",
       "      <td>16.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>0.99282</td>\n",
       "      <td>3.49</td>\n",
       "      <td>0.49</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4875</th>\n",
       "      <td>7.4</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.26</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.035</td>\n",
       "      <td>18.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>0.99245</td>\n",
       "      <td>3.12</td>\n",
       "      <td>0.41</td>\n",
       "      <td>9.700000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4876</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.380</td>\n",
       "      <td>0.42</td>\n",
       "      <td>2.50</td>\n",
       "      <td>0.038</td>\n",
       "      <td>34.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>0.99132</td>\n",
       "      <td>3.36</td>\n",
       "      <td>0.59</td>\n",
       "      <td>11.600000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4877</th>\n",
       "      <td>5.9</td>\n",
       "      <td>0.540</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.032</td>\n",
       "      <td>12.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>0.99286</td>\n",
       "      <td>3.25</td>\n",
       "      <td>0.36</td>\n",
       "      <td>8.800000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4878</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.530</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.90</td>\n",
       "      <td>0.035</td>\n",
       "      <td>6.0</td>\n",
       "      <td>81.0</td>\n",
       "      <td>0.99234</td>\n",
       "      <td>3.24</td>\n",
       "      <td>0.35</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4879</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.340</td>\n",
       "      <td>0.40</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0.046</td>\n",
       "      <td>68.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>0.99494</td>\n",
       "      <td>3.15</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.533333</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4880</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.340</td>\n",
       "      <td>0.40</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0.046</td>\n",
       "      <td>68.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>0.99494</td>\n",
       "      <td>3.15</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.533333</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4881</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.235</td>\n",
       "      <td>0.27</td>\n",
       "      <td>11.75</td>\n",
       "      <td>0.030</td>\n",
       "      <td>34.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>0.99540</td>\n",
       "      <td>3.07</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.400000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4882</th>\n",
       "      <td>5.5</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.13</td>\n",
       "      <td>1.30</td>\n",
       "      <td>0.037</td>\n",
       "      <td>45.0</td>\n",
       "      <td>156.0</td>\n",
       "      <td>0.99184</td>\n",
       "      <td>3.26</td>\n",
       "      <td>0.38</td>\n",
       "      <td>10.700000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4883</th>\n",
       "      <td>4.9</td>\n",
       "      <td>0.470</td>\n",
       "      <td>0.17</td>\n",
       "      <td>1.90</td>\n",
       "      <td>0.035</td>\n",
       "      <td>60.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>0.98964</td>\n",
       "      <td>3.27</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.500000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4884</th>\n",
       "      <td>6.5</td>\n",
       "      <td>0.330</td>\n",
       "      <td>0.38</td>\n",
       "      <td>8.30</td>\n",
       "      <td>0.048</td>\n",
       "      <td>68.0</td>\n",
       "      <td>174.0</td>\n",
       "      <td>0.99492</td>\n",
       "      <td>3.14</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4885</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.340</td>\n",
       "      <td>0.40</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0.046</td>\n",
       "      <td>68.0</td>\n",
       "      <td>170.0</td>\n",
       "      <td>0.99494</td>\n",
       "      <td>3.15</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.550000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4886</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.210</td>\n",
       "      <td>0.28</td>\n",
       "      <td>5.70</td>\n",
       "      <td>0.028</td>\n",
       "      <td>45.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>0.99168</td>\n",
       "      <td>3.21</td>\n",
       "      <td>1.08</td>\n",
       "      <td>12.150000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4887</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.410</td>\n",
       "      <td>0.22</td>\n",
       "      <td>1.90</td>\n",
       "      <td>0.023</td>\n",
       "      <td>5.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>0.98928</td>\n",
       "      <td>3.04</td>\n",
       "      <td>0.79</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4888</th>\n",
       "      <td>6.8</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.36</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.052</td>\n",
       "      <td>38.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>0.99330</td>\n",
       "      <td>3.04</td>\n",
       "      <td>0.54</td>\n",
       "      <td>9.200000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4889</th>\n",
       "      <td>4.9</td>\n",
       "      <td>0.235</td>\n",
       "      <td>0.27</td>\n",
       "      <td>11.75</td>\n",
       "      <td>0.030</td>\n",
       "      <td>34.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>0.99540</td>\n",
       "      <td>3.07</td>\n",
       "      <td>0.50</td>\n",
       "      <td>9.400000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4890</th>\n",
       "      <td>6.1</td>\n",
       "      <td>0.340</td>\n",
       "      <td>0.29</td>\n",
       "      <td>2.20</td>\n",
       "      <td>0.036</td>\n",
       "      <td>25.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>0.98938</td>\n",
       "      <td>3.06</td>\n",
       "      <td>0.44</td>\n",
       "      <td>11.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4891</th>\n",
       "      <td>5.7</td>\n",
       "      <td>0.210</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.90</td>\n",
       "      <td>0.038</td>\n",
       "      <td>38.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>0.99074</td>\n",
       "      <td>3.24</td>\n",
       "      <td>0.46</td>\n",
       "      <td>10.600000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4892</th>\n",
       "      <td>6.5</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.38</td>\n",
       "      <td>1.30</td>\n",
       "      <td>0.032</td>\n",
       "      <td>29.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>0.99298</td>\n",
       "      <td>3.29</td>\n",
       "      <td>0.54</td>\n",
       "      <td>9.700000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4893</th>\n",
       "      <td>6.2</td>\n",
       "      <td>0.210</td>\n",
       "      <td>0.29</td>\n",
       "      <td>1.60</td>\n",
       "      <td>0.039</td>\n",
       "      <td>24.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>0.99114</td>\n",
       "      <td>3.27</td>\n",
       "      <td>0.50</td>\n",
       "      <td>11.200000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4894</th>\n",
       "      <td>6.6</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.36</td>\n",
       "      <td>8.00</td>\n",
       "      <td>0.047</td>\n",
       "      <td>57.0</td>\n",
       "      <td>168.0</td>\n",
       "      <td>0.99490</td>\n",
       "      <td>3.15</td>\n",
       "      <td>0.46</td>\n",
       "      <td>9.600000</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4895</th>\n",
       "      <td>6.5</td>\n",
       "      <td>0.240</td>\n",
       "      <td>0.19</td>\n",
       "      <td>1.20</td>\n",
       "      <td>0.041</td>\n",
       "      <td>30.0</td>\n",
       "      <td>111.0</td>\n",
       "      <td>0.99254</td>\n",
       "      <td>2.99</td>\n",
       "      <td>0.46</td>\n",
       "      <td>9.400000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4896</th>\n",
       "      <td>5.5</td>\n",
       "      <td>0.290</td>\n",
       "      <td>0.30</td>\n",
       "      <td>1.10</td>\n",
       "      <td>0.022</td>\n",
       "      <td>20.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>0.98869</td>\n",
       "      <td>3.34</td>\n",
       "      <td>0.38</td>\n",
       "      <td>12.800000</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4897</th>\n",
       "      <td>6.0</td>\n",
       "      <td>0.210</td>\n",
       "      <td>0.38</td>\n",
       "      <td>0.80</td>\n",
       "      <td>0.020</td>\n",
       "      <td>22.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>0.98941</td>\n",
       "      <td>3.26</td>\n",
       "      <td>0.32</td>\n",
       "      <td>11.800000</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4898 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Fixed acidity  Volatile acidity  Citric acid  Residual sugar  Chlorides  \\\n",
       "0               7.0             0.270         0.36           20.70      0.045   \n",
       "1               6.3             0.300         0.34            1.60      0.049   \n",
       "2               8.1             0.280         0.40            6.90      0.050   \n",
       "3               7.2             0.230         0.32            8.50      0.058   \n",
       "4               7.2             0.230         0.32            8.50      0.058   \n",
       "5               8.1             0.280         0.40            6.90      0.050   \n",
       "6               6.2             0.320         0.16            7.00      0.045   \n",
       "7               7.0             0.270         0.36           20.70      0.045   \n",
       "8               6.3             0.300         0.34            1.60      0.049   \n",
       "9               8.1             0.220         0.43            1.50      0.044   \n",
       "10              8.1             0.270         0.41            1.45      0.033   \n",
       "11              8.6             0.230         0.40            4.20      0.035   \n",
       "12              7.9             0.180         0.37            1.20      0.040   \n",
       "13              6.6             0.160         0.40            1.50      0.044   \n",
       "14              8.3             0.420         0.62           19.25      0.040   \n",
       "15              6.6             0.170         0.38            1.50      0.032   \n",
       "16              6.3             0.480         0.04            1.10      0.046   \n",
       "17              6.2             0.660         0.48            1.20      0.029   \n",
       "18              7.4             0.340         0.42            1.10      0.033   \n",
       "19              6.5             0.310         0.14            7.50      0.044   \n",
       "20              6.2             0.660         0.48            1.20      0.029   \n",
       "21              6.4             0.310         0.38            2.90      0.038   \n",
       "22              6.8             0.260         0.42            1.70      0.049   \n",
       "23              7.6             0.670         0.14            1.50      0.074   \n",
       "24              6.6             0.270         0.41            1.30      0.052   \n",
       "25              7.0             0.250         0.32            9.00      0.046   \n",
       "26              6.9             0.240         0.35            1.00      0.052   \n",
       "27              7.0             0.280         0.39            8.70      0.051   \n",
       "28              7.4             0.270         0.48            1.10      0.047   \n",
       "29              7.2             0.320         0.36            2.00      0.033   \n",
       "...             ...               ...          ...             ...        ...   \n",
       "4868            5.8             0.230         0.31            4.50      0.046   \n",
       "4869            6.6             0.240         0.33           10.10      0.032   \n",
       "4870            6.1             0.320         0.28            6.60      0.021   \n",
       "4871            5.0             0.200         0.40            1.90      0.015   \n",
       "4872            6.0             0.420         0.41           12.40      0.032   \n",
       "4873            5.7             0.210         0.32            1.60      0.030   \n",
       "4874            5.6             0.200         0.36            2.50      0.048   \n",
       "4875            7.4             0.220         0.26            1.20      0.035   \n",
       "4876            6.2             0.380         0.42            2.50      0.038   \n",
       "4877            5.9             0.540         0.00            0.80      0.032   \n",
       "4878            6.2             0.530         0.02            0.90      0.035   \n",
       "4879            6.6             0.340         0.40            8.10      0.046   \n",
       "4880            6.6             0.340         0.40            8.10      0.046   \n",
       "4881            5.0             0.235         0.27           11.75      0.030   \n",
       "4882            5.5             0.320         0.13            1.30      0.037   \n",
       "4883            4.9             0.470         0.17            1.90      0.035   \n",
       "4884            6.5             0.330         0.38            8.30      0.048   \n",
       "4885            6.6             0.340         0.40            8.10      0.046   \n",
       "4886            6.2             0.210         0.28            5.70      0.028   \n",
       "4887            6.2             0.410         0.22            1.90      0.023   \n",
       "4888            6.8             0.220         0.36            1.20      0.052   \n",
       "4889            4.9             0.235         0.27           11.75      0.030   \n",
       "4890            6.1             0.340         0.29            2.20      0.036   \n",
       "4891            5.7             0.210         0.32            0.90      0.038   \n",
       "4892            6.5             0.230         0.38            1.30      0.032   \n",
       "4893            6.2             0.210         0.29            1.60      0.039   \n",
       "4894            6.6             0.320         0.36            8.00      0.047   \n",
       "4895            6.5             0.240         0.19            1.20      0.041   \n",
       "4896            5.5             0.290         0.30            1.10      0.022   \n",
       "4897            6.0             0.210         0.38            0.80      0.020   \n",
       "\n",
       "      Free sulfur dioxide  Total sulfur dioxide  Density    pH  Sulphates  \\\n",
       "0                    45.0                 170.0  1.00100  3.00       0.45   \n",
       "1                    14.0                 132.0  0.99400  3.30       0.49   \n",
       "2                    30.0                  97.0  0.99510  3.26       0.44   \n",
       "3                    47.0                 186.0  0.99560  3.19       0.40   \n",
       "4                    47.0                 186.0  0.99560  3.19       0.40   \n",
       "5                    30.0                  97.0  0.99510  3.26       0.44   \n",
       "6                    30.0                 136.0  0.99490  3.18       0.47   \n",
       "7                    45.0                 170.0  1.00100  3.00       0.45   \n",
       "8                    14.0                 132.0  0.99400  3.30       0.49   \n",
       "9                    28.0                 129.0  0.99380  3.22       0.45   \n",
       "10                   11.0                  63.0  0.99080  2.99       0.56   \n",
       "11                   17.0                 109.0  0.99470  3.14       0.53   \n",
       "12                   16.0                  75.0  0.99200  3.18       0.63   \n",
       "13                   48.0                 143.0  0.99120  3.54       0.52   \n",
       "14                   41.0                 172.0  1.00020  2.98       0.67   \n",
       "15                   28.0                 112.0  0.99140  3.25       0.55   \n",
       "16                   30.0                  99.0  0.99280  3.24       0.36   \n",
       "17                   29.0                  75.0  0.98920  3.33       0.39   \n",
       "18                   17.0                 171.0  0.99170  3.12       0.53   \n",
       "19                   34.0                 133.0  0.99550  3.22       0.50   \n",
       "20                   29.0                  75.0  0.98920  3.33       0.39   \n",
       "21                   19.0                 102.0  0.99120  3.17       0.35   \n",
       "22                   41.0                 122.0  0.99300  3.47       0.48   \n",
       "23                   25.0                 168.0  0.99370  3.05       0.51   \n",
       "24                   16.0                 142.0  0.99510  3.42       0.47   \n",
       "25                   56.0                 245.0  0.99550  3.25       0.50   \n",
       "26                   35.0                 146.0  0.99300  3.45       0.44   \n",
       "27                   32.0                 141.0  0.99610  3.38       0.53   \n",
       "28                   17.0                 132.0  0.99140  3.19       0.49   \n",
       "29                   37.0                 114.0  0.99060  3.10       0.71   \n",
       "...                   ...                   ...      ...   ...        ...   \n",
       "4868                 42.0                 124.0  0.99324  3.31       0.64   \n",
       "4869                  8.0                  81.0  0.99626  3.19       0.51   \n",
       "4870                 29.0                 132.0  0.99188  3.15       0.36   \n",
       "4871                 20.0                  98.0  0.98970  3.37       0.55   \n",
       "4872                 50.0                 179.0  0.99622  3.14       0.60   \n",
       "4873                 33.0                 122.0  0.99044  3.33       0.52   \n",
       "4874                 16.0                 125.0  0.99282  3.49       0.49   \n",
       "4875                 18.0                  97.0  0.99245  3.12       0.41   \n",
       "4876                 34.0                 117.0  0.99132  3.36       0.59   \n",
       "4877                 12.0                  82.0  0.99286  3.25       0.36   \n",
       "4878                  6.0                  81.0  0.99234  3.24       0.35   \n",
       "4879                 68.0                 170.0  0.99494  3.15       0.50   \n",
       "4880                 68.0                 170.0  0.99494  3.15       0.50   \n",
       "4881                 34.0                 118.0  0.99540  3.07       0.50   \n",
       "4882                 45.0                 156.0  0.99184  3.26       0.38   \n",
       "4883                 60.0                 148.0  0.98964  3.27       0.35   \n",
       "4884                 68.0                 174.0  0.99492  3.14       0.50   \n",
       "4885                 68.0                 170.0  0.99494  3.15       0.50   \n",
       "4886                 45.0                 121.0  0.99168  3.21       1.08   \n",
       "4887                  5.0                  56.0  0.98928  3.04       0.79   \n",
       "4888                 38.0                 127.0  0.99330  3.04       0.54   \n",
       "4889                 34.0                 118.0  0.99540  3.07       0.50   \n",
       "4890                 25.0                 100.0  0.98938  3.06       0.44   \n",
       "4891                 38.0                 121.0  0.99074  3.24       0.46   \n",
       "4892                 29.0                 112.0  0.99298  3.29       0.54   \n",
       "4893                 24.0                  92.0  0.99114  3.27       0.50   \n",
       "4894                 57.0                 168.0  0.99490  3.15       0.46   \n",
       "4895                 30.0                 111.0  0.99254  2.99       0.46   \n",
       "4896                 20.0                 110.0  0.98869  3.34       0.38   \n",
       "4897                 22.0                  98.0  0.98941  3.26       0.32   \n",
       "\n",
       "        Alcohol  Quality  \n",
       "0      8.800000        6  \n",
       "1      9.500000        6  \n",
       "2     10.100000        6  \n",
       "3      9.900000        6  \n",
       "4      9.900000        6  \n",
       "5     10.100000        6  \n",
       "6      9.600000        6  \n",
       "7      8.800000        6  \n",
       "8      9.500000        6  \n",
       "9     11.000000        6  \n",
       "10    12.000000        5  \n",
       "11     9.700000        5  \n",
       "12    10.800000        5  \n",
       "13    12.400000        7  \n",
       "14     9.700000        5  \n",
       "15    11.400000        7  \n",
       "16     9.600000        6  \n",
       "17    12.800000        8  \n",
       "18    11.300000        6  \n",
       "19     9.500000        5  \n",
       "20    12.800000        8  \n",
       "21    11.000000        7  \n",
       "22    10.500000        8  \n",
       "23     9.300000        5  \n",
       "24    10.000000        6  \n",
       "25    10.400000        6  \n",
       "26    10.000000        6  \n",
       "27    10.500000        6  \n",
       "28    11.600000        6  \n",
       "29    12.300000        7  \n",
       "...         ...      ...  \n",
       "4868  10.800000        6  \n",
       "4869   9.800000        6  \n",
       "4870  11.450000        7  \n",
       "4871  12.050000        6  \n",
       "4872   9.700000        5  \n",
       "4873  11.900000        6  \n",
       "4874  10.000000        6  \n",
       "4875   9.700000        6  \n",
       "4876  11.600000        7  \n",
       "4877   8.800000        5  \n",
       "4878   9.500000        4  \n",
       "4879   9.533333        6  \n",
       "4880   9.533333        6  \n",
       "4881   9.400000        6  \n",
       "4882  10.700000        5  \n",
       "4883  11.500000        6  \n",
       "4884   9.600000        5  \n",
       "4885   9.550000        6  \n",
       "4886  12.150000        7  \n",
       "4887  13.000000        7  \n",
       "4888   9.200000        5  \n",
       "4889   9.400000        6  \n",
       "4890  11.800000        6  \n",
       "4891  10.600000        6  \n",
       "4892   9.700000        5  \n",
       "4893  11.200000        6  \n",
       "4894   9.600000        5  \n",
       "4895   9.400000        6  \n",
       "4896  12.800000        7  \n",
       "4897  11.800000        6  \n",
       "\n",
       "[4898 rows x 12 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('winequality-white.csv',names = ['Fixed acidity','Volatile acidity','Citric acid','Residual sugar','Chlorides','Free sulfur dioxide','Total sulfur dioxide','Density','pH','Sulphates','Alcohol','Quality'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "for f in ['Fixed acidity','Volatile acidity','Citric acid','Residual sugar','Chlorides','Free sulfur dioxide','Total sulfur dioxide','Density','pH','Sulphates','Alcohol']:\n",
    "    df[f] = df[f].astype('category')\n",
    "    df[f] = df[f].cat.codes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Fixed acidity</th>\n",
       "      <th>Volatile acidity</th>\n",
       "      <th>Citric acid</th>\n",
       "      <th>Residual sugar</th>\n",
       "      <th>Chlorides</th>\n",
       "      <th>Free sulfur dioxide</th>\n",
       "      <th>Total sulfur dioxide</th>\n",
       "      <th>Density</th>\n",
       "      <th>pH</th>\n",
       "      <th>Sulphates</th>\n",
       "      <th>Alcohol</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>31</td>\n",
       "      <td>36</td>\n",
       "      <td>36</td>\n",
       "      <td>302</td>\n",
       "      <td>34</td>\n",
       "      <td>57</td>\n",
       "      <td>146</td>\n",
       "      <td>878</td>\n",
       "      <td>23</td>\n",
       "      <td>22</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23</td>\n",
       "      <td>42</td>\n",
       "      <td>34</td>\n",
       "      <td>17</td>\n",
       "      <td>38</td>\n",
       "      <td>13</td>\n",
       "      <td>106</td>\n",
       "      <td>471</td>\n",
       "      <td>53</td>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>43</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>101</td>\n",
       "      <td>39</td>\n",
       "      <td>33</td>\n",
       "      <td>69</td>\n",
       "      <td>560</td>\n",
       "      <td>49</td>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>34</td>\n",
       "      <td>28</td>\n",
       "      <td>32</td>\n",
       "      <td>128</td>\n",
       "      <td>47</td>\n",
       "      <td>59</td>\n",
       "      <td>163</td>\n",
       "      <td>601</td>\n",
       "      <td>42</td>\n",
       "      <td>17</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>34</td>\n",
       "      <td>28</td>\n",
       "      <td>32</td>\n",
       "      <td>128</td>\n",
       "      <td>47</td>\n",
       "      <td>59</td>\n",
       "      <td>163</td>\n",
       "      <td>601</td>\n",
       "      <td>42</td>\n",
       "      <td>17</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>43</td>\n",
       "      <td>38</td>\n",
       "      <td>40</td>\n",
       "      <td>101</td>\n",
       "      <td>39</td>\n",
       "      <td>33</td>\n",
       "      <td>69</td>\n",
       "      <td>560</td>\n",
       "      <td>49</td>\n",
       "      <td>21</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>22</td>\n",
       "      <td>46</td>\n",
       "      <td>16</td>\n",
       "      <td>103</td>\n",
       "      <td>34</td>\n",
       "      <td>33</td>\n",
       "      <td>110</td>\n",
       "      <td>544</td>\n",
       "      <td>41</td>\n",
       "      <td>24</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>31</td>\n",
       "      <td>36</td>\n",
       "      <td>36</td>\n",
       "      <td>302</td>\n",
       "      <td>34</td>\n",
       "      <td>57</td>\n",
       "      <td>146</td>\n",
       "      <td>878</td>\n",
       "      <td>23</td>\n",
       "      <td>22</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>23</td>\n",
       "      <td>42</td>\n",
       "      <td>34</td>\n",
       "      <td>17</td>\n",
       "      <td>38</td>\n",
       "      <td>13</td>\n",
       "      <td>106</td>\n",
       "      <td>471</td>\n",
       "      <td>53</td>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>43</td>\n",
       "      <td>26</td>\n",
       "      <td>43</td>\n",
       "      <td>15</td>\n",
       "      <td>33</td>\n",
       "      <td>30</td>\n",
       "      <td>102</td>\n",
       "      <td>453</td>\n",
       "      <td>45</td>\n",
       "      <td>22</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>43</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "      <td>14</td>\n",
       "      <td>22</td>\n",
       "      <td>9</td>\n",
       "      <td>35</td>\n",
       "      <td>194</td>\n",
       "      <td>22</td>\n",
       "      <td>33</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>48</td>\n",
       "      <td>28</td>\n",
       "      <td>40</td>\n",
       "      <td>56</td>\n",
       "      <td>24</td>\n",
       "      <td>17</td>\n",
       "      <td>81</td>\n",
       "      <td>527</td>\n",
       "      <td>37</td>\n",
       "      <td>30</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>41</td>\n",
       "      <td>19</td>\n",
       "      <td>37</td>\n",
       "      <td>9</td>\n",
       "      <td>29</td>\n",
       "      <td>16</td>\n",
       "      <td>47</td>\n",
       "      <td>300</td>\n",
       "      <td>41</td>\n",
       "      <td>40</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>27</td>\n",
       "      <td>15</td>\n",
       "      <td>40</td>\n",
       "      <td>15</td>\n",
       "      <td>33</td>\n",
       "      <td>60</td>\n",
       "      <td>117</td>\n",
       "      <td>230</td>\n",
       "      <td>77</td>\n",
       "      <td>29</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>45</td>\n",
       "      <td>66</td>\n",
       "      <td>62</td>\n",
       "      <td>288</td>\n",
       "      <td>29</td>\n",
       "      <td>49</td>\n",
       "      <td>148</td>\n",
       "      <td>863</td>\n",
       "      <td>21</td>\n",
       "      <td>44</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>27</td>\n",
       "      <td>17</td>\n",
       "      <td>38</td>\n",
       "      <td>15</td>\n",
       "      <td>21</td>\n",
       "      <td>30</td>\n",
       "      <td>84</td>\n",
       "      <td>249</td>\n",
       "      <td>48</td>\n",
       "      <td>32</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>23</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>35</td>\n",
       "      <td>33</td>\n",
       "      <td>71</td>\n",
       "      <td>370</td>\n",
       "      <td>47</td>\n",
       "      <td>13</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>22</td>\n",
       "      <td>103</td>\n",
       "      <td>48</td>\n",
       "      <td>9</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "      <td>47</td>\n",
       "      <td>59</td>\n",
       "      <td>56</td>\n",
       "      <td>16</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>36</td>\n",
       "      <td>50</td>\n",
       "      <td>42</td>\n",
       "      <td>7</td>\n",
       "      <td>22</td>\n",
       "      <td>17</td>\n",
       "      <td>147</td>\n",
       "      <td>274</td>\n",
       "      <td>35</td>\n",
       "      <td>30</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>26</td>\n",
       "      <td>44</td>\n",
       "      <td>14</td>\n",
       "      <td>112</td>\n",
       "      <td>33</td>\n",
       "      <td>38</td>\n",
       "      <td>107</td>\n",
       "      <td>593</td>\n",
       "      <td>45</td>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>22</td>\n",
       "      <td>103</td>\n",
       "      <td>48</td>\n",
       "      <td>9</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "      <td>47</td>\n",
       "      <td>59</td>\n",
       "      <td>56</td>\n",
       "      <td>16</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>24</td>\n",
       "      <td>44</td>\n",
       "      <td>38</td>\n",
       "      <td>39</td>\n",
       "      <td>27</td>\n",
       "      <td>19</td>\n",
       "      <td>74</td>\n",
       "      <td>230</td>\n",
       "      <td>40</td>\n",
       "      <td>12</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>29</td>\n",
       "      <td>34</td>\n",
       "      <td>42</td>\n",
       "      <td>19</td>\n",
       "      <td>38</td>\n",
       "      <td>49</td>\n",
       "      <td>95</td>\n",
       "      <td>387</td>\n",
       "      <td>70</td>\n",
       "      <td>25</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>38</td>\n",
       "      <td>104</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>63</td>\n",
       "      <td>27</td>\n",
       "      <td>144</td>\n",
       "      <td>445</td>\n",
       "      <td>28</td>\n",
       "      <td>28</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>27</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "      <td>11</td>\n",
       "      <td>41</td>\n",
       "      <td>16</td>\n",
       "      <td>116</td>\n",
       "      <td>560</td>\n",
       "      <td>65</td>\n",
       "      <td>24</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>31</td>\n",
       "      <td>32</td>\n",
       "      <td>32</td>\n",
       "      <td>137</td>\n",
       "      <td>35</td>\n",
       "      <td>72</td>\n",
       "      <td>229</td>\n",
       "      <td>593</td>\n",
       "      <td>48</td>\n",
       "      <td>27</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "      <td>35</td>\n",
       "      <td>5</td>\n",
       "      <td>41</td>\n",
       "      <td>39</td>\n",
       "      <td>120</td>\n",
       "      <td>387</td>\n",
       "      <td>68</td>\n",
       "      <td>21</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>31</td>\n",
       "      <td>38</td>\n",
       "      <td>39</td>\n",
       "      <td>132</td>\n",
       "      <td>40</td>\n",
       "      <td>36</td>\n",
       "      <td>115</td>\n",
       "      <td>641</td>\n",
       "      <td>61</td>\n",
       "      <td>30</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>36</td>\n",
       "      <td>36</td>\n",
       "      <td>48</td>\n",
       "      <td>7</td>\n",
       "      <td>36</td>\n",
       "      <td>17</td>\n",
       "      <td>106</td>\n",
       "      <td>249</td>\n",
       "      <td>42</td>\n",
       "      <td>26</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>34</td>\n",
       "      <td>46</td>\n",
       "      <td>36</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "      <td>42</td>\n",
       "      <td>86</td>\n",
       "      <td>175</td>\n",
       "      <td>33</td>\n",
       "      <td>48</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4868</th>\n",
       "      <td>17</td>\n",
       "      <td>28</td>\n",
       "      <td>31</td>\n",
       "      <td>62</td>\n",
       "      <td>35</td>\n",
       "      <td>51</td>\n",
       "      <td>97</td>\n",
       "      <td>409</td>\n",
       "      <td>54</td>\n",
       "      <td>41</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4869</th>\n",
       "      <td>27</td>\n",
       "      <td>30</td>\n",
       "      <td>33</td>\n",
       "      <td>155</td>\n",
       "      <td>21</td>\n",
       "      <td>6</td>\n",
       "      <td>53</td>\n",
       "      <td>650</td>\n",
       "      <td>42</td>\n",
       "      <td>28</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4870</th>\n",
       "      <td>20</td>\n",
       "      <td>46</td>\n",
       "      <td>28</td>\n",
       "      <td>95</td>\n",
       "      <td>10</td>\n",
       "      <td>32</td>\n",
       "      <td>106</td>\n",
       "      <td>290</td>\n",
       "      <td>38</td>\n",
       "      <td>13</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4871</th>\n",
       "      <td>9</td>\n",
       "      <td>22</td>\n",
       "      <td>40</td>\n",
       "      <td>23</td>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "      <td>70</td>\n",
       "      <td>100</td>\n",
       "      <td>60</td>\n",
       "      <td>32</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4872</th>\n",
       "      <td>19</td>\n",
       "      <td>66</td>\n",
       "      <td>41</td>\n",
       "      <td>186</td>\n",
       "      <td>21</td>\n",
       "      <td>63</td>\n",
       "      <td>156</td>\n",
       "      <td>647</td>\n",
       "      <td>37</td>\n",
       "      <td>37</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4873</th>\n",
       "      <td>16</td>\n",
       "      <td>24</td>\n",
       "      <td>32</td>\n",
       "      <td>17</td>\n",
       "      <td>19</td>\n",
       "      <td>37</td>\n",
       "      <td>95</td>\n",
       "      <td>160</td>\n",
       "      <td>56</td>\n",
       "      <td>29</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4874</th>\n",
       "      <td>15</td>\n",
       "      <td>22</td>\n",
       "      <td>36</td>\n",
       "      <td>33</td>\n",
       "      <td>37</td>\n",
       "      <td>16</td>\n",
       "      <td>98</td>\n",
       "      <td>372</td>\n",
       "      <td>72</td>\n",
       "      <td>26</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4875</th>\n",
       "      <td>36</td>\n",
       "      <td>26</td>\n",
       "      <td>26</td>\n",
       "      <td>9</td>\n",
       "      <td>24</td>\n",
       "      <td>18</td>\n",
       "      <td>69</td>\n",
       "      <td>339</td>\n",
       "      <td>35</td>\n",
       "      <td>18</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4876</th>\n",
       "      <td>22</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>33</td>\n",
       "      <td>27</td>\n",
       "      <td>38</td>\n",
       "      <td>90</td>\n",
       "      <td>241</td>\n",
       "      <td>59</td>\n",
       "      <td>36</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4877</th>\n",
       "      <td>18</td>\n",
       "      <td>85</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>11</td>\n",
       "      <td>54</td>\n",
       "      <td>375</td>\n",
       "      <td>48</td>\n",
       "      <td>13</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4878</th>\n",
       "      <td>22</td>\n",
       "      <td>84</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>24</td>\n",
       "      <td>4</td>\n",
       "      <td>53</td>\n",
       "      <td>328</td>\n",
       "      <td>47</td>\n",
       "      <td>12</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4879</th>\n",
       "      <td>27</td>\n",
       "      <td>50</td>\n",
       "      <td>40</td>\n",
       "      <td>121</td>\n",
       "      <td>35</td>\n",
       "      <td>88</td>\n",
       "      <td>146</td>\n",
       "      <td>546</td>\n",
       "      <td>38</td>\n",
       "      <td>27</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4880</th>\n",
       "      <td>27</td>\n",
       "      <td>50</td>\n",
       "      <td>40</td>\n",
       "      <td>121</td>\n",
       "      <td>35</td>\n",
       "      <td>88</td>\n",
       "      <td>146</td>\n",
       "      <td>546</td>\n",
       "      <td>38</td>\n",
       "      <td>27</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4881</th>\n",
       "      <td>9</td>\n",
       "      <td>29</td>\n",
       "      <td>27</td>\n",
       "      <td>176</td>\n",
       "      <td>19</td>\n",
       "      <td>38</td>\n",
       "      <td>91</td>\n",
       "      <td>585</td>\n",
       "      <td>30</td>\n",
       "      <td>27</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4882</th>\n",
       "      <td>14</td>\n",
       "      <td>46</td>\n",
       "      <td>13</td>\n",
       "      <td>11</td>\n",
       "      <td>26</td>\n",
       "      <td>57</td>\n",
       "      <td>130</td>\n",
       "      <td>287</td>\n",
       "      <td>49</td>\n",
       "      <td>15</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4883</th>\n",
       "      <td>8</td>\n",
       "      <td>75</td>\n",
       "      <td>17</td>\n",
       "      <td>23</td>\n",
       "      <td>24</td>\n",
       "      <td>77</td>\n",
       "      <td>122</td>\n",
       "      <td>96</td>\n",
       "      <td>50</td>\n",
       "      <td>12</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4884</th>\n",
       "      <td>26</td>\n",
       "      <td>48</td>\n",
       "      <td>38</td>\n",
       "      <td>125</td>\n",
       "      <td>37</td>\n",
       "      <td>88</td>\n",
       "      <td>150</td>\n",
       "      <td>545</td>\n",
       "      <td>37</td>\n",
       "      <td>27</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4885</th>\n",
       "      <td>27</td>\n",
       "      <td>50</td>\n",
       "      <td>40</td>\n",
       "      <td>121</td>\n",
       "      <td>35</td>\n",
       "      <td>88</td>\n",
       "      <td>146</td>\n",
       "      <td>546</td>\n",
       "      <td>38</td>\n",
       "      <td>27</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4886</th>\n",
       "      <td>22</td>\n",
       "      <td>24</td>\n",
       "      <td>28</td>\n",
       "      <td>82</td>\n",
       "      <td>17</td>\n",
       "      <td>57</td>\n",
       "      <td>94</td>\n",
       "      <td>273</td>\n",
       "      <td>44</td>\n",
       "      <td>78</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4887</th>\n",
       "      <td>22</td>\n",
       "      <td>64</td>\n",
       "      <td>22</td>\n",
       "      <td>23</td>\n",
       "      <td>12</td>\n",
       "      <td>3</td>\n",
       "      <td>28</td>\n",
       "      <td>64</td>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4888</th>\n",
       "      <td>29</td>\n",
       "      <td>26</td>\n",
       "      <td>36</td>\n",
       "      <td>9</td>\n",
       "      <td>41</td>\n",
       "      <td>43</td>\n",
       "      <td>100</td>\n",
       "      <td>414</td>\n",
       "      <td>27</td>\n",
       "      <td>31</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4889</th>\n",
       "      <td>8</td>\n",
       "      <td>29</td>\n",
       "      <td>27</td>\n",
       "      <td>176</td>\n",
       "      <td>19</td>\n",
       "      <td>38</td>\n",
       "      <td>91</td>\n",
       "      <td>585</td>\n",
       "      <td>30</td>\n",
       "      <td>27</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4890</th>\n",
       "      <td>20</td>\n",
       "      <td>50</td>\n",
       "      <td>29</td>\n",
       "      <td>28</td>\n",
       "      <td>25</td>\n",
       "      <td>27</td>\n",
       "      <td>72</td>\n",
       "      <td>71</td>\n",
       "      <td>29</td>\n",
       "      <td>21</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4891</th>\n",
       "      <td>16</td>\n",
       "      <td>24</td>\n",
       "      <td>32</td>\n",
       "      <td>3</td>\n",
       "      <td>27</td>\n",
       "      <td>43</td>\n",
       "      <td>94</td>\n",
       "      <td>188</td>\n",
       "      <td>47</td>\n",
       "      <td>23</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4892</th>\n",
       "      <td>26</td>\n",
       "      <td>28</td>\n",
       "      <td>38</td>\n",
       "      <td>11</td>\n",
       "      <td>21</td>\n",
       "      <td>32</td>\n",
       "      <td>84</td>\n",
       "      <td>385</td>\n",
       "      <td>52</td>\n",
       "      <td>31</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4893</th>\n",
       "      <td>22</td>\n",
       "      <td>24</td>\n",
       "      <td>29</td>\n",
       "      <td>17</td>\n",
       "      <td>28</td>\n",
       "      <td>26</td>\n",
       "      <td>64</td>\n",
       "      <td>224</td>\n",
       "      <td>50</td>\n",
       "      <td>27</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4894</th>\n",
       "      <td>27</td>\n",
       "      <td>46</td>\n",
       "      <td>36</td>\n",
       "      <td>120</td>\n",
       "      <td>36</td>\n",
       "      <td>73</td>\n",
       "      <td>144</td>\n",
       "      <td>544</td>\n",
       "      <td>38</td>\n",
       "      <td>23</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4895</th>\n",
       "      <td>26</td>\n",
       "      <td>30</td>\n",
       "      <td>19</td>\n",
       "      <td>9</td>\n",
       "      <td>30</td>\n",
       "      <td>33</td>\n",
       "      <td>83</td>\n",
       "      <td>347</td>\n",
       "      <td>22</td>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4896</th>\n",
       "      <td>14</td>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>7</td>\n",
       "      <td>11</td>\n",
       "      <td>21</td>\n",
       "      <td>82</td>\n",
       "      <td>29</td>\n",
       "      <td>57</td>\n",
       "      <td>15</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4897</th>\n",
       "      <td>19</td>\n",
       "      <td>24</td>\n",
       "      <td>38</td>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>23</td>\n",
       "      <td>70</td>\n",
       "      <td>74</td>\n",
       "      <td>49</td>\n",
       "      <td>9</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4898 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Fixed acidity  Volatile acidity  Citric acid  Residual sugar  Chlorides  \\\n",
       "0                31                36           36             302         34   \n",
       "1                23                42           34              17         38   \n",
       "2                43                38           40             101         39   \n",
       "3                34                28           32             128         47   \n",
       "4                34                28           32             128         47   \n",
       "5                43                38           40             101         39   \n",
       "6                22                46           16             103         34   \n",
       "7                31                36           36             302         34   \n",
       "8                23                42           34              17         38   \n",
       "9                43                26           43              15         33   \n",
       "10               43                36           41              14         22   \n",
       "11               48                28           40              56         24   \n",
       "12               41                19           37               9         29   \n",
       "13               27                15           40              15         33   \n",
       "14               45                66           62             288         29   \n",
       "15               27                17           38              15         21   \n",
       "16               23                77            4               7         35   \n",
       "17               22               103           48               9         18   \n",
       "18               36                50           42               7         22   \n",
       "19               26                44           14             112         33   \n",
       "20               22               103           48               9         18   \n",
       "21               24                44           38              39         27   \n",
       "22               29                34           42              19         38   \n",
       "23               38               104           14              15         63   \n",
       "24               27                36           41              11         41   \n",
       "25               31                32           32             137         35   \n",
       "26               30                30           35               5         41   \n",
       "27               31                38           39             132         40   \n",
       "28               36                36           48               7         36   \n",
       "29               34                46           36              25         22   \n",
       "...             ...               ...          ...             ...        ...   \n",
       "4868             17                28           31              62         35   \n",
       "4869             27                30           33             155         21   \n",
       "4870             20                46           28              95         10   \n",
       "4871              9                22           40              23          4   \n",
       "4872             19                66           41             186         21   \n",
       "4873             16                24           32              17         19   \n",
       "4874             15                22           36              33         37   \n",
       "4875             36                26           26               9         24   \n",
       "4876             22                58           42              33         27   \n",
       "4877             18                85            0               2         21   \n",
       "4878             22                84            2               3         24   \n",
       "4879             27                50           40             121         35   \n",
       "4880             27                50           40             121         35   \n",
       "4881              9                29           27             176         19   \n",
       "4882             14                46           13              11         26   \n",
       "4883              8                75           17              23         24   \n",
       "4884             26                48           38             125         37   \n",
       "4885             27                50           40             121         35   \n",
       "4886             22                24           28              82         17   \n",
       "4887             22                64           22              23         12   \n",
       "4888             29                26           36               9         41   \n",
       "4889              8                29           27             176         19   \n",
       "4890             20                50           29              28         25   \n",
       "4891             16                24           32               3         27   \n",
       "4892             26                28           38              11         21   \n",
       "4893             22                24           29              17         28   \n",
       "4894             27                46           36             120         36   \n",
       "4895             26                30           19               9         30   \n",
       "4896             14                40           30               7         11   \n",
       "4897             19                24           38               2          9   \n",
       "\n",
       "      Free sulfur dioxide  Total sulfur dioxide  Density  pH  Sulphates  \\\n",
       "0                      57                   146      878  23         22   \n",
       "1                      13                   106      471  53         26   \n",
       "2                      33                    69      560  49         21   \n",
       "3                      59                   163      601  42         17   \n",
       "4                      59                   163      601  42         17   \n",
       "5                      33                    69      560  49         21   \n",
       "6                      33                   110      544  41         24   \n",
       "7                      57                   146      878  23         22   \n",
       "8                      13                   106      471  53         26   \n",
       "9                      30                   102      453  45         22   \n",
       "10                      9                    35      194  22         33   \n",
       "11                     17                    81      527  37         30   \n",
       "12                     16                    47      300  41         40   \n",
       "13                     60                   117      230  77         29   \n",
       "14                     49                   148      863  21         44   \n",
       "15                     30                    84      249  48         32   \n",
       "16                     33                    71      370  47         13   \n",
       "17                     32                    47       59  56         16   \n",
       "18                     17                   147      274  35         30   \n",
       "19                     38                   107      593  45         27   \n",
       "20                     32                    47       59  56         16   \n",
       "21                     19                    74      230  40         12   \n",
       "22                     49                    95      387  70         25   \n",
       "23                     27                   144      445  28         28   \n",
       "24                     16                   116      560  65         24   \n",
       "25                     72                   229      593  48         27   \n",
       "26                     39                   120      387  68         21   \n",
       "27                     36                   115      641  61         30   \n",
       "28                     17                   106      249  42         26   \n",
       "29                     42                    86      175  33         48   \n",
       "...                   ...                   ...      ...  ..        ...   \n",
       "4868                   51                    97      409  54         41   \n",
       "4869                    6                    53      650  42         28   \n",
       "4870                   32                   106      290  38         13   \n",
       "4871                   21                    70      100  60         32   \n",
       "4872                   63                   156      647  37         37   \n",
       "4873                   37                    95      160  56         29   \n",
       "4874                   16                    98      372  72         26   \n",
       "4875                   18                    69      339  35         18   \n",
       "4876                   38                    90      241  59         36   \n",
       "4877                   11                    54      375  48         13   \n",
       "4878                    4                    53      328  47         12   \n",
       "4879                   88                   146      546  38         27   \n",
       "4880                   88                   146      546  38         27   \n",
       "4881                   38                    91      585  30         27   \n",
       "4882                   57                   130      287  49         15   \n",
       "4883                   77                   122       96  50         12   \n",
       "4884                   88                   150      545  37         27   \n",
       "4885                   88                   146      546  38         27   \n",
       "4886                   57                    94      273  44         78   \n",
       "4887                    3                    28       64  27         56   \n",
       "4888                   43                   100      414  27         31   \n",
       "4889                   38                    91      585  30         27   \n",
       "4890                   27                    72       71  29         21   \n",
       "4891                   43                    94      188  47         23   \n",
       "4892                   32                    84      385  52         31   \n",
       "4893                   26                    64      224  50         27   \n",
       "4894                   73                   144      544  38         23   \n",
       "4895                   33                    83      347  22         23   \n",
       "4896                   21                    82       29  57         15   \n",
       "4897                   23                    70       74  49          9   \n",
       "\n",
       "      Alcohol  \n",
       "0           5  \n",
       "1          12  \n",
       "2          24  \n",
       "3          21  \n",
       "4          21  \n",
       "5          24  \n",
       "6          15  \n",
       "7           5  \n",
       "8          12  \n",
       "9          43  \n",
       "10         70  \n",
       "11         17  \n",
       "12         38  \n",
       "13         79  \n",
       "14         17  \n",
       "15         53  \n",
       "16         15  \n",
       "17         84  \n",
       "18         49  \n",
       "19         12  \n",
       "20         84  \n",
       "21         43  \n",
       "22         31  \n",
       "23         10  \n",
       "24         22  \n",
       "25         29  \n",
       "26         22  \n",
       "27         31  \n",
       "28         59  \n",
       "29         77  \n",
       "...       ...  \n",
       "4868       38  \n",
       "4869       20  \n",
       "4870       55  \n",
       "4871       71  \n",
       "4872       17  \n",
       "4873       67  \n",
       "4874       22  \n",
       "4875       17  \n",
       "4876       59  \n",
       "4877        5  \n",
       "4878       12  \n",
       "4879       13  \n",
       "4880       13  \n",
       "4881       11  \n",
       "4882       37  \n",
       "4883       57  \n",
       "4884       15  \n",
       "4885       14  \n",
       "4886       74  \n",
       "4887       87  \n",
       "4888        9  \n",
       "4889       11  \n",
       "4890       65  \n",
       "4891       35  \n",
       "4892       17  \n",
       "4893       47  \n",
       "4894       15  \n",
       "4895       11  \n",
       "4896       84  \n",
       "4897       65  \n",
       "\n",
       "[4898 rows x 11 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features = ['Fixed acidity','Volatile acidity','Citric acid','Residual sugar','Chlorides','Free sulfur dioxide','Total sulfur dioxide','Density','pH','Sulphates','Alcohol']\n",
    "X = df.get(features)\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 6, 6, ..., 6, 7, 6])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y = df['Quality'].values\n",
    "\n",
    "Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.46268657  0.29032258  0.41860465 ...,  0.28205128  0.04901961  6.        ]\n",
      " [ 0.34328358  0.33870968  0.39534884 ...,  0.33333333  0.11764706  6.        ]\n",
      " [ 0.64179104  0.30645161  0.46511628 ...,  0.26923077  0.23529412  6.        ]\n",
      " ..., \n",
      " [ 0.3880597   0.24193548  0.22093023 ...,  0.29487179  0.10784314  6.        ]\n",
      " [ 0.20895522  0.32258065  0.34883721 ...,  0.19230769  0.82352941  7.        ]\n",
      " [ 0.28358209  0.19354839  0.44186047 ...,  0.11538462  0.6372549   6.        ]]\n"
     ]
    }
   ],
   "source": [
    "X = MinMaxScaler().fit_transform(X)\n",
    "ds = np.column_stack([X, Y])\n",
    "print(ds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "train, test = train_test_split(ds, test_size = 0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3.4372468792770579, 0.75279408697817674, -0.10682648284960305, 0.65109074416130897, 0.26724739674730158, 0.24069893769521539, 0.58866343802600818, 0.21559000394083616, 0.08267330561094198, 1.1595444849965131, 0.64305285251194866, 2.1200709998305198]\n"
     ]
    }
   ],
   "source": [
    "l_rate = 0.0001\n",
    "n_epoch = 100\n",
    "\n",
    "coefs = coefficients_sgd(train, l_rate, n_epoch)\n",
    "print(coefs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "predictions = list()\n",
    "for row in test:\n",
    "    predicted = predict(row, coefs)\n",
    "    predictions.append(predicted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_test = list()\n",
    "for i in range(1470):\n",
    "    y_test.append(test[i][11])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "predicted = predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "soma = 0\n",
    "for i in range(len(y_test)):\n",
    "    erro = predicted[i] - y_test[i]\n",
    "    soma += (erro**2)\n",
    "    erroMedio = soma/float(len(y_test))\n",
    "acc = sqrt(erroMedio)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8005400689392048"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
